package com.glink.manage.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glink.common.exception.GeneralSimpleException;
import com.glink.manage.domain.ConstructionWorkAccessMonadBean;
import com.glink.manage.dto.constructionwork.*;
import com.glink.manage.dto.person.PersonAccessMonadPageDTO;
import com.glink.manage.vo.constructionwork.ConstructionWorkAccessMonadDetailsVO;
import com.glink.manage.vo.constructionwork.ConstructionWorkAccessMonadPageVO;
import com.glink.manage.vo.constructionwork.ConstructionWorkListVO;
import com.glink.manage.vo.person.PersonAccessMonadPageVO;

import java.util.Date;
import java.util.List;

/**
 * @author  qiushaoshan
 * @since  2025-01-13
 */
public interface ConstructionWorkAccessMonadService extends IService<ConstructionWorkAccessMonadBean> {

    /**
     * 分页查询准入申请审批单
     * @param dto 分页查询条件
     * @return 准入申请单
     */
    IPage<PersonAccessMonadPageVO> pageByAccessMonad(PersonAccessMonadPageDTO dto);

    /**
     * 新增准入申请
     * @param dto 准入申请信息
     * @return 新增状态
     */
    boolean insertAccessMonad(ConstructionWorkAccessMonadSaveDTO dto) throws GeneralSimpleException;

    /**
     * 查询可办理准入的工程
     * @param dto 查询条件
     * @return 工程信息
     */
    List<ConstructionWorkListVO> findWorkList(ConstructionWorkAccessMonadListDTO dto) throws GeneralSimpleException;

    /**
     * 撤回申请单
     * @param dto 申请单ID
     * @return 撤回状态
     */
    Boolean withdraw(ConstructionWorkAccessMonadWithdrawDTO dto) throws GeneralSimpleException;

    /**
     * 查询准入工程ID
     * @param associationObjId 关联ID
     * @param keyApprovalFormStatus 审批单状态
     * @return 工程ID
     */
    List<String> findWorkIdByAssociationObjIdAndTypeAndAccessStatus(String associationObjId, String keyApprovalFormStatus, String accessStatus);

    /**
     * 同意审批
     * @param dto 审批单信息
     * @return 同意状态
     */
    Boolean agreeApprove(ConstructionWorkAccessMonadAgreeDTO dto) throws GeneralSimpleException;

    /**
     * 驳回审批
     * @param dto 驳回信息
     * @return 驳回状态
     */
    Boolean rejectApprove(ConstructionWorkAccessMonadRejectDTO dto) throws GeneralSimpleException;

    /**
     * 查询申请单详情
     * @param dto 申请单ID
     * @return 申请单详情
     */
    ConstructionWorkAccessMonadDetailsVO findDetailById(ConstructionWorkAccessMonadIdDTO dto) throws GeneralSimpleException;

    /**
     * 分页查询待审批列表
     * @param dto 查询条件
     * @return 审批单信息
     */
    IPage<ConstructionWorkAccessMonadPageVO> pageByPendingApproval(ConstructionWorkAccessMonadPageDTO dto) throws GeneralSimpleException;

    /**
     * 分页查询已审批列表
     * @param dto 查询条件
     * @return 审批单信息
     */
    IPage<ConstructionWorkAccessMonadPageVO> pageByApproval(ConstructionWorkAccessMonadPageDTO dto) throws GeneralSimpleException;

    /**
     * 统计待审批单子数量
     */
    
    void countPendingApproval();

    /**
     * 保存审批单
     * @param constructionWorkAccessMonadBean 审批单实体
     * @return 保存状态
     */
    boolean saveBean(ConstructionWorkAccessMonadBean constructionWorkAccessMonadBean);

    /**
     * 根据审批单ID查询审批单
     * @param accessMonadObjId 审批单ID
     * @return 审批状态
     */
    ConstructionWorkAccessMonadBean findByObjId(String accessMonadObjId);

    /**
     * 根据审批单ID更新审批单状态
     * @param accessStatus 审批状态
     * @param objId 审批单ID
     * @return 更新状态
     */
    boolean updateAccessStatusByObjId(String accessStatus, String objId);

    /**
     * 查询人员ID
     *
     * @param personObjIdList  关联ID
     * @param approvalFormType 审批单类型
     * @param accessStatus     准入状态
     * @param nowDate 当前时间
     * @return 关联ID
     */
    List<String> findPersonObjIdByAssociationObjIdInAndTypeAndAccessStatus(List<String> personObjIdList, String approvalFormType, String accessStatus, Date nowDate);

    /**
     * 查询审批单ID
     * @param workIdList 工程ID
     * @param typeList 审批单类型
     * @param accessStatus 准入状态
     * @return 审批单ID
     */
    List<String> findObjIdByWorkIdInAndTypeInAndAccessStatus(List<String> workIdList, List<String> typeList, String accessStatus);

    /**
     * 查询审批单ID
     * @param typeList 审批单类型
     * @param accessStatus 准入状态
     * @return 审批单ID
     */
    List<String> findObjIdByTypeInAndAccessStatus(List<String> typeList, String accessStatus);

    /**
     * 更新审批单信息
     * @param accessStatus 审批状态
     * @param cycleStart 开始时间
     * @param cycleEnd 结束时间
     * @param constructionWorkObjId 工程
     * @param objId 审批单ID
     * @return 状态
     */
    boolean updateAccessStatusAndCycleStartAndCycleEndAndConstructionWorkObjIdByObjId(String accessStatus, Date cycleStart, Date cycleEnd, String constructionWorkObjId, String objId);
}
